| Total Complexity | 3 | 
| Total Lines | 33 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | import { CommandHandler } from '@nestjs/cqrs'; | 
            ||
| 8 | |||
| 9 | @CommandHandler(UpdateContactCommand)  | 
            ||
| 10 | export class UpdateContactCommandHandler { | 
            ||
| 11 | constructor(  | 
            ||
| 12 |     @Inject('IContactRepository') | 
            ||
| 13 | private readonly contactRepository: IContactRepository,  | 
            ||
| 14 | private readonly isContactEmpty: IsContactEmpty  | 
            ||
| 15 |   ) {} | 
            ||
| 16 | |||
| 17 |   public async execute(command: UpdateContactCommand): Promise<void> { | 
            ||
| 18 |     const { | 
            ||
| 19 | id,  | 
            ||
| 20 | firstName,  | 
            ||
| 21 | lastName,  | 
            ||
| 22 | company,  | 
            ||
| 23 | email,  | 
            ||
| 24 | phoneNumber,  | 
            ||
| 25 | notes  | 
            ||
| 26 | } = command;  | 
            ||
| 27 | |||
| 28 | const contact = await this.contactRepository.findOneById(id);  | 
            ||
| 29 | |||
| 30 |     if (!contact) { | 
            ||
| 31 | throw new ContactNotFoundException();  | 
            ||
| 32 | }  | 
            ||
| 33 | |||
| 34 |     if (this.isContactEmpty.isSatisfiedBy(firstName, lastName, company)) { | 
            ||
| 35 | throw new EmptyContactException();  | 
            ||
| 36 | }  | 
            ||
| 37 | |||
| 38 | contact.update(firstName, lastName, company, email, phoneNumber, notes);  | 
            ||
| 39 | |||
| 40 | await this.contactRepository.save(contact);  | 
            ||
| 41 | }  | 
            ||
| 43 |